# -*- coding: utf-8 -*-
"""
date: Fri Dec 14 14:20:45 2018
python: Anaconda 3.6.5
author: kanade
email: kanade@blisst.cn
"""
import numpy as np
import matplotlib.pyplot as mp


# 生成数据
apples = np.array([30, 25, 22, 36, 21, 29,
                   20, 24, 33, 19, 27, 15])
oranges = np.array([24, 33, 19, 27, 35, 20,
                    15, 27, 20, 32, 20, 22])
durian = np.array([115, 88, 66, 68, 102, 92,
                   44, 59, 105, 96, 98, 75])
# 创建图形窗口
mp.figure('Bar', facecolor='lightgray')
# 设置窗口标题
mp.title('Bar', fontsize=20)
# 设置坐标轴标签
mp.xlabel('Month', fontsize=14)
mp.ylabel('Price', fontsize=14)
# 设置刻度参数
mp.tick_params(labelsize=10)
# 设置网格线型
mp.grid(axis='y', linestyle=':')
# 设置垂直坐标范围
mp.ylim(-40, 120)
# 绘制条形图
x = np.arange(len(apples))
mp.bar(x, -apples, 0.4, color='dodgerblue',
       label='Apple')
# 加0.4是为了不和Apple重合
mp.bar(x + 0.4,-oranges, 0.4, color='orangered',
       label='Orange', alpha=0.75)

mp.bar(x + 0.2, durian, 0.6, color='turquoise',
       label='Durian')
# 设置水平坐标刻度标签,加0.1只是为了好看
mp.xticks(x + 0.1, (
    'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
    'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))
# 绘制图例
mp.legend()
# 显示图形
mp.show()
